package com.example.hf_v1.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

@Configuration

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = "" +request.getHeader("token");

        if (token.isEmpty()) {
            Result.errorLogin("用户未登录，请先登录");
            return false;
        } else {
            if(("浪花骑士向你致以诚挚的问候").equals(token)){
                return true;
            }else {
                Result.errorLogin("用户登录失败，请重新登录");
                return false;
            }
        }
    }
}
